package cn.fl.capital.service.impl;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

import cmm.comm.facade.framework.api.ISysCtrlCfgApiService;
import cmm.comm.facade.framework.condition.SysCtrlCfgQueryCondition;
import cn.fl.commons.result.ResponseData;
import cn.fl.export.api.ICapFundExportApiService;
import cn.fl.export.condition.CapFundExportCondition;
import cn.fl.project.vo.BillItemVO;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.shiqiao.fl.repay.bill.dto.BillInfoDTO;
import com.shiqiao.fl.repay.bill.dto.BillItemDTO;
import com.shiqiao.fl.repay.bill.facade.IRepayBillApiService;
import com.shiqiao.fl.repay.bill.request.QueryPeriodBillInfoParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.constant.SysDictionaryConstant;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cmm.user.facade.system.api.ISysOrgApiService;
import cmm.user.facade.system.api.ISysUsrApiService;
import cmm.user.facade.system.dto.SysOrgDTO;
import cmm.user.facade.system.dto.SysUsrDTO;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.capital.condition.CapFundQueryCondition;
import cn.fl.capital.condition.CapOverdueInfoQueryCondition;
import cn.fl.capital.constant.CapPayInfoConstant;
import cn.fl.capital.constant.CapitalConstant;
import cn.fl.capital.dto.CapFundDTO;
import cn.fl.capital.dto.CapOverdueInfoDTO;
import cn.fl.capital.dto.CapPayInfoDTO;
import cn.fl.capital.service.ICapFundApiService;
import cn.fl.capital.service.ICapFundService;
import cn.fl.capital.service.ICapFundVfDtlApiService;
import cn.fl.capital.service.ICapFundVfLogApiService;
import cn.fl.capital.service.ICapOverdueInfoApiService;
import cn.fl.capital.transform.CapFundVOTransform;
import cn.fl.capital.transform.CapPayInfoVOTransform;
import cn.fl.capital.vo.CapFundOutLogVO;
import cn.fl.capital.vo.CapFundVO;
import cn.fl.capital.vo.CapPayInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.project.condition.PrjPrdPaySchDQueryCondition;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.project.constant.PrjPrdPaySchDConstant;
import cn.fl.project.dto.PrjPrdPaySchDDTO;
import cn.fl.project.service.IPrjPrdDtlService;
import cn.fl.project.service.IPrjPrdPaySchDApiService;
import cn.fl.project.service.IPrjPrdPaySchMApiService;
import cn.fl.project.transform.PrjPrdDtlVOTransform;
import cn.fl.project.transform.PrjPrdPaySchDVOTransform;
import cn.fl.project.vo.PrjPrdDtlVO;
import cn.fl.project.vo.PrjPrdPaySchDVO;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import fl.customer.facade.customer.api.ICustomerQueryApiService;
import fl.customer.facade.customer.condition.CstBscInfoQueryCondition;
import fl.customer.facade.customer.dto.CstBscInfoDTO;
import fl.flow.facade.flow.api.IFlowQueryApiService;
import fl.flow.facade.flow.condition.SysFlowSHQueryCondition;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.SysFlowSHDTO;

/**
 * @Description: 客户资金表 客户端服务层接口实现
 * 业务层方法名称前缀：
 * 新增：add*
 * 删除：remove*
 * 修改：modify*
 * 批量：batch*
 * 查询对象：select* get*
 * 查询集合：search*
 */
@Service
public class CapFundServiceImpl implements ICapFundService {

    /**
     * 日志
     */
    @SuppressWarnings("unused")
    private static final Logger logger = LoggerFactory.getLogger(CapFundServiceImpl.class);

    /**
     * 资金暴露服务
     */
    @Autowired
    private ICapFundExportApiService capFundExportApiService;
    @Autowired
    private ICapFundApiService capFundApiService;
    @Autowired
    private ICapFundVfDtlApiService capFundVfDtlApiService;
    /**
     * 数据字典服务
     */
    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService;
    @Autowired
    private ISysUsrApiService sysUsrApiService;
    @Autowired
    private ISysOrgApiService sysOrgApiService;
    @Autowired
    private IPrjPrdPaySchDApiService prjPrdPaySchDApiService;
    @Autowired
    private IPrjPrdPaySchMApiService prjPrdPaySchMApiService;
    @Autowired
    private ICapOverdueInfoApiService capOverdueInfoApiService;
    @Autowired
    private ICustomerQueryApiService customerQueryApiService;
    @Autowired
    private IFlowQueryApiService flowQueryApiService;
    @Autowired
    private IPrjPrdDtlService prjPrdDtlService;
    @Autowired
    private ICapFundVfLogApiService capFundVfLogApiService ;
    @Autowired
    private IRepayBillApiService repayBillApiService;
    @Autowired
    private ISysCtrlCfgApiService sysCtrlCfgApiService;

    @Override
    public CapFundVO selectById(Long id) throws BaseException {
        if (StringUtils.isEmpty(id)) return null;
        CapFundDTO dto = this.capFundApiService.selectCapFundById(id);
        //查询创建人名称
        if (StringUtils.isNotEmpty(dto.getCrtUsrId())) {
            SysUsrDTO usrDTO = sysUsrApiService.selectSysUsrById(dto.getCrtUsrId(), CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
            if (usrDTO != null) {
                dto.setCrtUsrNm(usrDTO.getUsrNm());
            }
        }
        if (StringUtils.isNotBlank(dto.getFundStatusCd())) {
            SysDictionaryDTO dict = this.sysDictionaryApiService.getCode(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), CapitalConstant.CODE_CAP_FUND_STS_CD, dto.getFundStatusCd());
            if (dict != null) {
                dto.setFundStatusCdNm(dict.getCodeNm());
            }
        }
        return CapFundVOTransform.toVO(dto);
    }

    @Override
    public Long add(CapFundVO entity) throws BaseException {
        if (null == entity) return null;
        return this.capFundApiService.addCapFund(CapFundVOTransform.toDTO(entity));
    }

    /**
     * 批量新增
     *
     * @param fundList
     * @return
     */
    public boolean add(List<CapFundVO> fundList) throws BaseException {
        if (CollectionUtils.isEmpty(fundList)) return false;
        return this.capFundApiService.addCapFund(CapFundVOTransform.toDTOList(fundList));
    }

    @Override
    public boolean removeByIds(List<Long> ids) throws BaseException {
        if (CollectionUtils.isEmpty(ids)) return false;
        return this.capFundApiService.removeCapFundByIds(ids, CurrentThreadContext.getCurrentUserId());
    }

    @Override
    public boolean modify(CapFundVO entity) throws BaseException {
        if (null == entity) return false;
        return this.capFundApiService.modifyCapFund(CapFundVOTransform.toDTO(entity));
    }

    @Override
    public Pager searchListPage(Pager page) throws BaseException {
        CapFundQueryCondition condition = null;
        if (null == page) {
            page = new Pager();
            page.setCondition(new CapFundQueryCondition());
        }
        condition = (CapFundQueryCondition) page.getCondition();
        condition.setSysCd(CurrentThreadContext.getCurrentSysCd());//当前系统代码
        condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());//当前机构代码
        condition.setUsrId(CurrentThreadContext.getCurrentUserId());//当前用户ID
        page = this.capFundApiService.searchCapFundListPage(page);
        if (CollectionUtils.isNotEmpty(page.getResultList())) {
            List<CapFundVO> voList = CapFundVOTransform.toVOList((List<CapFundDTO>) page.getResultList());
            this.setDictData(voList);
            page.setResultList(voList);
        }
        return page;
    }

    @Override
    public List<CapFundVO> searchList(CapFundQueryCondition condition) throws BaseException {
        if (null == condition) condition = new CapFundQueryCondition();
        condition.setSysCd(CurrentThreadContext.getCurrentSysCd());//当前系统代码
        condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());//当前机构代码
        condition.setUsrId(CurrentThreadContext.getCurrentUserId());//当前用户ID
        List<CapFundVO> voList = CapFundVOTransform.toVOList(this.capFundApiService.searchCapFundList(condition));
        this.setDictData(voList);
        return voList;
    }


    /**
     * 手动认款，修改资金所属客户信息
     *
     * @param entity
     * @return
     * @throws BaseException
     */
    public DataResultVO modifyFundCstInfo(CapFundVO entity) throws BaseException {
        if (null == entity) return new DataResultVO(BaseConstant.IS_YESNO_NO,"资金参数不能为空！");
        DataResultDTO dataResultDTO = this.capFundApiService.modifyFundCstInfo(CapFundVOTransform.toDTO(entity));
        return new DataResultVO(Integer.valueOf(dataResultDTO.getCode()),dataResultDTO.getInfo(),null == dataResultDTO.getData() ? "" :dataResultDTO.getData());
    }

    /**
     * 自动认款，批量修改资金所属客户信息
     *
     * @param condition
     * @return
     * @throws BaseException
     */
    public List<CapFundVO> batchModifyFundCstInfo(CapFundQueryCondition condition) throws BaseException {
        return CapFundVOTransform.toVOList(this.capFundApiService.batchModifyFundCstInfo(condition));
    }

    /*****************************************
     * 资金分解 单笔资金手动分解
     *
     * @param condition  资金condition
     * @param schDVOList 支付表明细VO集合
     * @return
     * @throws BaseException
     ******************************************/
    @Override
    public DataResultVO addFundDecompose(CapFundQueryCondition condition, List<PrjPrdPaySchDVO> schDVOList) throws BaseException {
        DataResultVO result = new DataResultVO();
        Long decTtlAmt = 0L;//本次分解总金额

        //查询资金信息
        CapFundDTO fundDTO = this.capFundApiService.selectCapFundById(condition.getId());
        if (fundDTO == null) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(CapitalConstant.CODE_FUND_VF_FAILED_REASON_0);
            return result;
        }
        fundDTO.setDocketRem(condition.getDocketRem());//备注

        //List<Long> idList = new ArrayList<>(schDVOList.size());
        List<Long> paySchIdList = new ArrayList<>(schDVOList.size());
        Map<Long, Long> actAmtMap = new HashMap<>(schDVOList.size());
        for (PrjPrdPaySchDVO schDVO : schDVOList) {
            //idList.add(schDVO.getId());
            if (!paySchIdList.contains(schDVO.getPaySchId())) {
                paySchIdList.add(schDVO.getPaySchId());
            }
            actAmtMap.put(schDVO.getId(), schDVO.getActAmt());
            decTtlAmt += schDVO.getActAmt();
        }

        //判断资金可用金额
        if (fundDTO.getAvailableAmount() < decTtlAmt) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(CapitalConstant.CODE_FUND_VF_FAILED_REASON_4);
            return result;
        }

        //查询客户待分解支付表
        condition.setCstId(fundDTO.getCstId());
        condition.setAdditionalCondition("'S04'");
        condition.setPaySchIdList(paySchIdList);
        condition.setAcceptActualDate(fundDTO.getAcceptActualDate());
        List<PrjPrdPaySchDDTO> paySchDDTOList = this.searchPrdPaySchDList(condition);
        if (CollectionUtils.isEmpty(paySchDDTOList)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(CapitalConstant.CODE_FUND_VF_FAILED_REASON);
            return result;
        }

        List<PrjPrdPaySchDDTO> decList = new ArrayList<>();//待分解支付表明细
        for (PrjPrdPaySchDDTO paySchDDTO : paySchDDTOList) {
            //排除掉租金
            if (CapitalConstant.CODE_FEE_TYP_CD_S01.equals(paySchDDTO.getFeeTypCd())) {
                decList.add(paySchDDTO);
                continue;
            }
            if (actAmtMap.containsKey(paySchDDTO.getId())) {
                Long actAmt = actAmtMap.get(paySchDDTO.getId());
                if (actAmt > paySchDDTO.getArAmt()) {
                    actAmt = paySchDDTO.getArAmt();
                }
                paySchDDTO.setActAmt(actAmt);
                decList.add(paySchDDTO);
            }
        }

        fundDTO.setFundDecomUsrId(CurrentThreadContext.getCurrentUserId());//分解人ID
        fundDTO.setFundDecomUsrNm(CurrentThreadContext.getCurrentUserName());//分解人名称
        DataResultDTO resultDTO = this.capFundVfDtlApiService.addManualDecompose(fundDTO, decList);
        if (null != resultDTO) {
            DataResultVO resultVO = new DataResultVO(Integer.parseInt(resultDTO.getCode()), resultDTO.getInfo());
            return resultVO;
        }
        return null;
    }

    /**
     * 资金分解 手动分解
     *
     * @param condition 资金condition
     * @return
     * @throws BaseException
     */
    @Override
    public DataResultVO addFundManualDecompose(CapFundQueryCondition condition) throws BaseException {
        try {

            //分解人ID
            condition.setFundDecomUsrId(CurrentThreadContext.getCurrentUserId());
            //分解人名称
            condition.setFundDecomUsrNm(CurrentThreadContext.getCurrentUserName());

            // 校验
            CapFundDTO capFundDTO = capFundApiService.selectCapFundById(condition.getId());
            if (null == capFundDTO || null == capFundDTO.getCstId()) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO,"资金信息错误");
            }

            QueryPeriodBillInfoParam queryParam = new QueryPeriodBillInfoParam();
            queryParam.setQueryCmd(QueryPeriodBillInfoParam.QueryCmd.QUERY_BY_CST_ID);
            queryParam.setQueryChannel(QueryPeriodBillInfoParam.QueryChannel.WEB_VF);
            queryParam.setCstId(capFundDTO.getCstId());
            queryParam.setQueryTime(capFundDTO.getAcceptActualDate());
            ResponseData<List<BillInfoDTO>> listResponseData = repayBillApiService.queryPeriodBillList(queryParam);
            if (!listResponseData.isSuccess() || CollectionUtils.isEmpty(listResponseData.getData())) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO,"校验账单信息异常");
            }
            Map<Long, BillInfoDTO> billIdToBillDTOMap = listResponseData.getData().stream()
                    .collect(Collectors.toMap(BillInfoDTO::getBillId, Function.identity()));

            List<PrjPrdPaySchDDTO> paySchDDTOList = null;
            try {
                paySchDDTOList = JSONObject.parseArray(condition.getAdditionalCondition(), PrjPrdPaySchDDTO.class);
                if (CollectionUtils.isEmpty(paySchDDTOList)) {
                    return new DataResultVO(BaseConstant.IS_YESNO_NO,"无待分解费用项");
                }
            } catch (Exception e) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO,"未选择待分解的费用项");
            }
            for (PrjPrdPaySchDDTO prjPrdPaySchDDTO : paySchDDTOList) {
                Long paySchId = prjPrdPaySchDDTO.getPaySchId();
                String paySchNo = prjPrdPaySchDDTO.getPaySchNo();
                String feeTypCd = prjPrdPaySchDDTO.getFeeTypCd();
                BillInfoDTO billInfoDTO = billIdToBillDTOMap.get(paySchId);
                if (null == billInfoDTO) {
                    return new DataResultVO(BaseConstant.IS_YESNO_NO,"选择的费用项异常，请刷新后再试");
                }
                // 当前只有车贷的本金利息罚息校验规则
                if("1".equals(billInfoDTO.getBusinessLine())){
                    if (CapitalConstant.CODE_FEE_TYP_CD_S02.equals(feeTypCd)
                            || CapitalConstant.CODE_FEE_TYP_CD_S03.equals(feeTypCd)
                            || CapitalConstant.CODE_FEE_TYP_CD_S05.equals(feeTypCd)) {
                        if (!Integer.valueOf(1).equals(billInfoDTO.getCanRepay())) {
                            String errorMsg = String.format("支付表%s： %s", paySchNo, billInfoDTO.getRepayPrompt());
                            return new DataResultVO(BaseConstant.IS_YESNO_NO, errorMsg);
                        }
                    }
                }
            }

            DataResultDTO resultDTO = this.capFundVfDtlApiService.addFundManualDecompose(condition);
            BaseLogUtils.info(logger,"addFundManualDecompose","来款"+condition.getId()+"手动分解返回==>"+JSON.toJSONString(resultDTO),CurrentThreadContext.getCurrentUserName());
            if (null != resultDTO) {
                /*if(null != resultDTO.getCode() && "1".equals(resultDTO.getCode())){
                    if(null != resultDTO.getData()){
                        Map<String,Object> map = (Map)resultDTO.getData();
                        if(CollectionUtils.isMapNotEmpty(map)){
                            if(map.containsKey("paySchIdList") && map.containsKey("cstId")){
                                List<Long> list = (List)map.get("paySchIdList");
                                Long cstId = (Long)map.get("cstId");
                                BaseLogUtils.info(logger, BaseExceptionConstant.BASE_EXCEPTION_CODE_200,"同步权证更新开始"+JSON.toJSONString(list)+"cstId = "+cstId);
                                this.capFundVfDtlApiService.toSyncPrdStatusAndQZByApi(list, cstId);
                                BaseLogUtils.info(logger,BaseExceptionConstant.BASE_EXCEPTION_CODE_200,"同步权证更新结束");
                            }
                        }
                    }
                }*/
                return new DataResultVO(Integer.parseInt(resultDTO.getCode()), resultDTO.getInfo());
            }else{
                return new DataResultVO(BaseConstant.IS_YESNO_NO,"来款手动分解失败");
            }
        } catch (BaseException e) {
            BaseLogUtils.error(logger,"addFundManualDecompose",CurrentThreadContext.getCurrentUserName()+"来款手动分解",e);
            return new DataResultVO(BaseConstant.IS_YESNO_NO,"来款手动分解异常");
        }
    }


    /**
     * 资金分解 手动分解【异常支付表】
     */
    @Override
    public DataResultVO addFundManualDecomposeAbnormal(CapFundQueryCondition condition) throws BaseException {
        try {
            //分解人ID
            condition.setFundDecomUsrId(CurrentThreadContext.getCurrentUserId());
            //分解人名称
            condition.setFundDecomUsrNm(CurrentThreadContext.getCurrentUserName());

            DataResultDTO resultDTO = this.capFundVfDtlApiService.addFundManualDecompose(condition);
            BaseLogUtils.info(logger,"addFundManualDecomposeAbnormal","来款"+condition.getId()+"手动分解返回==>"+JSON.toJSONString(resultDTO),CurrentThreadContext.getCurrentUserName());
            if (null != resultDTO) {
                /*if(null != resultDTO.getCode() && "1".equals(resultDTO.getCode())){
                    if(null != resultDTO.getData()){
                        Map<String,Object> map = (Map)resultDTO.getData();
                        if(CollectionUtils.isMapNotEmpty(map)){
                            if(map.containsKey("paySchIdList") && map.containsKey("cstId")){
                                List<Long> list = (List)map.get("paySchIdList");
                                Long cstId = (Long)map.get("cstId");
                                BaseLogUtils.info(logger, BaseExceptionConstant.BASE_EXCEPTION_CODE_200,"同步权证更新开始"+JSON.toJSONString(list)+"cstId = "+cstId);
                                this.capFundVfDtlApiService.toSyncPrdStatusAndQZByApi(list, cstId);
                                BaseLogUtils.info(logger,BaseExceptionConstant.BASE_EXCEPTION_CODE_200,"同步权证更新结束");
                            }
                        }
                    }
                }*/
                return new DataResultVO(Integer.parseInt(resultDTO.getCode()), resultDTO.getInfo());
            }else{
                return new DataResultVO(BaseConstant.IS_YESNO_NO,"来款手动分解失败");
            }
        } catch (BaseException e) {
            BaseLogUtils.error(logger,"addFundManualDecomposeAbnormal",CurrentThreadContext.getCurrentUserName()+"来款手动分解",e);
            return new DataResultVO(BaseConstant.IS_YESNO_NO,"来款手动分解异常");
        }
    }

    /**
     * 来款自动核销-批量分解
     *
     * @param condition 分解条件
     * @return
     */
    @Override
    public DataResultVO batchDecomFund(CapFundQueryCondition condition) throws BaseException {
        //分解人ID
        condition.setFundDecomUsrId(CurrentThreadContext.getCurrentUserId());
        //分解人名称
        condition.setFundDecomUsrNm(CurrentThreadContext.getCurrentUserName());
        try {
            DataResultDTO resultDTO = this.capFundVfDtlApiService.autoDecomposeFund(condition);
            if (resultDTO != null) {
                DataResultVO resultVO = new DataResultVO(Integer.parseInt(resultDTO.getCode()), resultDTO.getInfo());
                if (null != resultDTO.getData()) {
                    List<CapFundDTO> fundDTOList = (List<CapFundDTO>) resultDTO.getData();
                    if (CollectionUtils.isNotEmpty(fundDTOList)) {
                        resultVO.setData(CapFundVOTransform.toVOList(fundDTOList));
                    }
                }
                return resultVO;
            }
        } catch (BaseException e) {
            BaseLogUtils.info(logger, "batchDecomFund", "来款自动核销批量分解失败=="+JSON.toJSONString(condition),e);
        }
        return new DataResultVO(BaseConstant.IS_YESNO_NO, "来款自动核销批量分解失败");
    }

    /**
     * 查询客户待分解支付表明细
     * <p>过滤掉已结清支付表
     *
     * @param condition
     * @return
     * @throws BaseException
     */
    private List<PrjPrdPaySchDDTO> searchPrdPaySchDList(CapFundQueryCondition condition) throws BaseException {
        PrjPrdPaySchDQueryCondition qc = new PrjPrdPaySchDQueryCondition();
        qc.setCstId(condition.getCstId());//客户ID
        //qc.setArAmtMin(0l);//最小剩余金额
        qc.setVfFlag(1);//未核销金额不为零就是未核销完，本金有可能为负
        if(StringUtils.isNotBlank(condition.getAdditionalCondition())&&condition.getAdditionalCondition().contains(",")){
           String[] feeTypCdArray = condition.getAdditionalCondition().split(",");
           if(null!= feeTypCdArray && feeTypCdArray.length>0){
               List<String> excludeFeeTypCdList = new ArrayList<>(feeTypCdArray.length);
               for(String feeTypCd : feeTypCdArray){
                   excludeFeeTypCdList.add(feeTypCd);
               }
               qc.setExcludedFeeTypCdList(excludeFeeTypCdList);
           }
        }else{
            qc.setExcludeFeeTyp(condition.getAdditionalCondition());//查询时排除费用类型 ？
        }
        //qc.setSortName("M.ID,D.PAY_PD,D.PAY_DT,D.FEE_TYP_CD");//排序字段
        qc.setSortName("PAY_SCH_ID,PAY_PD,FEE_TYP_CD");//排序字段
        if (StringUtils.isNotEmpty(condition.getPayPd())) {//只核销首期时使用
            qc.setPayPd(condition.getPayPd());
            if(condition.getPayPd()>0L){
                //是否已起租
                qc.setIsStartRent(BaseConstant.IS_YESNO_YES);
            }
        }else{
            //是否已起租
            qc.setIsStartRent(BaseConstant.IS_YESNO_YES);
        }
        if (StringUtils.isNotEmpty(condition.getPaySchId())) {
            qc.setPaySchId(condition.getPaySchId());
        }
        if (CollectionUtils.isNotEmpty(condition.getPaySchIdList())) {
            qc.setPaySchIdList(condition.getPaySchIdList());
        }
       
        //过滤掉已结清的支付表
        List<KeyValueVO> kvList = this.sysDictionaryApiService.getKvListWithAttr1(CapitalConstant.CODE_CAP_PRD_STS_CD, "1", CapitalConstant.SYSCD, CapitalConstant.SYSORG);
        //已结清资产状态集合
        List<String> prdStsCdList = null;
        if (CollectionUtils.isNotEmpty(kvList)) {
            prdStsCdList = new ArrayList<>(kvList.size());
            for (KeyValueVO kv : kvList) {
                prdStsCdList.add(kv.getKey());
            }
            qc.setExcludedPrdStsCdList(prdStsCdList);
        }
        
        //查询所有业务支付表详细集合（我司与浙商）
        qc.setIsAllBiz(1);

        //查询是否需要开启手动分解未启用支付表
        SysDictionaryDTO dictionaryDTO = this.sysDictionaryApiService.getCode(CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),"CAP0068","decomFlag");
        if(null != dictionaryDTO && "1".equals(dictionaryDTO.getCodeNm())){
            qc.setIsEnable(-1);
        }
        BaseLogUtils.info(logger, "searchPaySchDList", "根据客户ID查询未核销完的支付表明细列表.DATA:" + JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
        List<PrjPrdPaySchDDTO> dtoList = prjPrdPaySchDApiService.searchVfPaySchDList(qc);
        // 贷款支付表明细 2017-12-22 10:18:39 jiangzg add -------------------------------
        List<PrjPrdPaySchDDTO> mcrBillDList = this.selectMcrBillList(condition);
        if (CollectionUtils.isNotEmpty(dtoList)) {
            for(PrjPrdPaySchDDTO ddto : dtoList){
                ddto.setBizTypCd("0");
            }
            if(CollectionUtils.isNotEmpty(mcrBillDList)){
                dtoList.addAll(mcrBillDList);
            }
        }else{
            if(CollectionUtils.isNotEmpty(mcrBillDList)){
                dtoList = mcrBillDList ;
            }
        }
        //开始查询垫款贷支付表明细
        BaseLogUtils.newLogger("pbl根据客户ID查询未核销完的支付表明细列表.condition:" + JSONObject.toJSONString(condition)).setKeys("searchPaySchDList",CurrentThreadContext.getCurrentUserName()).info();
        List<PrjPrdPaySchDDTO> pblBillDList = this.selectPblBillList(condition);
        BaseLogUtils.newLogger("pbl根据客户ID查询未核销完的支付表明细列表.condition:" + JSONObject.toJSONString(condition)).setKeys("searchPaySchDList",CurrentThreadContext.getCurrentUserName()).info();
        if (CollectionUtils.isNotEmpty(dtoList)) {
            if(CollectionUtils.isNotEmpty(pblBillDList)){
                dtoList.addAll(pblBillDList);
            }
        }else{
            if(CollectionUtils.isNotEmpty(pblBillDList)){
                dtoList = pblBillDList ;
            }
        }
        /******* 库存融资 ***start*******/
        if (StringUtils.isNotEmpty(condition.getType()) && "1".equals(condition.getType())) {
        	 List<PrjPrdPaySchDDTO> kcrzList = prjPrdPaySchDApiService.searchKcrzVfPaySchDList(qc);
             if (CollectionUtils.isNotEmpty(kcrzList)) {
             	if (CollectionUtils.isNotEmpty(dtoList)) {
             		dtoList.addAll(kcrzList);
             	}else{
             		dtoList = kcrzList;
             	}
             }
        }
        /******* 库存融资 ***end*******/
        
        // 贷款支付表明细 2017-12-22 10:18:39 jiangzg add -------------------------------
        if (CollectionUtils.isNotEmpty(dtoList)) {
            Map<Long, CapOverdueInfoDTO> ovdMap = null;//客户逾期支付表明细
            if (StringUtils.isEmpty(condition.getPayPd())) {
                //查询客户支付表罚息，逾期创建日期=资金到账日期
                CapOverdueInfoQueryCondition oqc = new CapOverdueInfoQueryCondition();
                oqc.setCstId(condition.getCstId());//客户ID
                oqc.setCreateDate(condition.getAcceptActualDate());//罚息日期
                List<String> overdueStatusCdList = new ArrayList<>();
                overdueStatusCdList.add("0");//未支付
                overdueStatusCdList.add("1");//部分支付
                oqc.setOverdueStatusCdList(overdueStatusCdList);
                if (StringUtils.isNotEmpty(condition.getPaySchId())) {
                    qc.setPaySchId(condition.getPaySchId());
                }
                if (CollectionUtils.isNotEmpty(condition.getPaySchIdList())) {
                    oqc.setPaySchIdList(condition.getPaySchIdList());
                } else {
                    List<Long> paySchIdList = new ArrayList<>(dtoList.size());
                    for (PrjPrdPaySchDDTO dto : dtoList) {
                        if (!paySchIdList.contains(dto.getPaySchId())) {
                            paySchIdList.add(dto.getPaySchId());
                        }
                    }

                    /*PrjPrdDtlQueryCondition prjPrdDtlQueryCondition = new PrjPrdDtlQueryCondition();
                    prjPrdDtlQueryCondition.setPaySchIdList(paySchIdList);
                    List<PrjPrdDtlVO> prjPrdDtlList = this.prjPrdDtlService.selectList(prjPrdDtlQueryCondition);
                    if (CollectionUtils.isEmpty(prjPrdDtlList)) {
                        BaseLogUtils.error(logger, "searchPrdPaySchDList", "查询客户待分解支付表明细,未查到支付表项目产品明细数据==" + JSON.toJSONString(paySchIdList));
                    } else {
                        //过滤掉已结清的支付表
                        List<KeyValueVO> kvList = this.sysDictionaryApiService.getKvListWithAttr1(CapitalConstant.CODE_CAP_PRD_STS_CD, "1", CapitalConstant.SYSCD, CapitalConstant.SYSORG);
                        //已结清资产状态集合
                        List<String> prdStsCdList = null;
                        if (CollectionUtils.isNotEmpty(kvList)) {
                            prdStsCdList = new ArrayList<>(kvList.size());
                            for (KeyValueVO kv : kvList) {
                                prdStsCdList.add(kv.getKey());
                            }
                            settledIdList = new ArrayList<>(prjPrdDtlList.size());
                            for (PrjPrdDtlVO vo : prjPrdDtlList) {
                                if (CollectionUtils.isNotEmpty(prdStsCdList) && prdStsCdList.contains(vo.getPrdStsCd())) {
                                    settledIdList.add(vo.getPaySchId());
                                }
                            }
                        }
                    }*/
                    oqc.setPaySchIdList(paySchIdList);
                }
                List<CapOverdueInfoDTO> overdueList = this.capOverdueInfoApiService.selectCapOverList(oqc);
                if (CollectionUtils.isNotEmpty(overdueList)) {
                    ovdMap = new HashMap<>(overdueList.size());
                    for (CapOverdueInfoDTO ovdDTO : overdueList) {
                        ovdMap.put(ovdDTO.getPaySchId(), ovdDTO);
                    }
                }
            }
            //支付表明细（包含首期费用项+罚息+支付表利息+本金）
            List<PrjPrdPaySchDDTO> paySchDDTOList = new ArrayList<>();
            //支付表0期计入期末款的费用项集合
            Map<Long, List<PrjPrdPaySchDDTO>> payLastMap = new HashMap<>();
            List<PrjPrdPaySchDDTO> tempList = null;
            Long paySchId = 0L;
            for (PrjPrdPaySchDDTO paySchDDTO : dtoList) {
                //过滤已结清的支付表
                /*if(CollectionUtils.isNotEmpty(settledIdList)&&settledIdList.contains(paySchDDTO.getPaySchId())){
                    continue;
                }*/
                //把计入期末款的费用项加到支付表费用项的末尾
                if(paySchId>0 && paySchId.compareTo(paySchDDTO.getPaySchId())==-1){
                    if(payLastMap.containsKey(paySchId)){
                        paySchDDTOList.addAll(payLastMap.get(paySchId));
                    }
                }
                //支付表ID
                paySchId = paySchDDTO.getPaySchId();

                //首付款不产生罚息, 并且计入融资额、合同额的支付表明细不需要核销
                if (paySchDDTO.getPayPd() == 0) {
                    if (CapitalConstant.CODE_CNT_WAY_CD_2.equals(paySchDDTO.getCntWayCd())
                            || CapitalConstant.CODE_CNT_WAY_CD_4.equals(paySchDDTO.getCntWayCd())) {
                        continue;
                    }
                    //计入期末款的最后核销
                    if (CapitalConstant.CODE_CNT_WAY_CD_5.equals(paySchDDTO.getCntWayCd())) {
                        if (payLastMap.containsKey(paySchDDTO.getPaySchId())) {
                            tempList = payLastMap.get(paySchDDTO.getPaySchId());
                        } else {
                            tempList = new ArrayList<>();
                        }
                        if (CapitalConstant.CODE_CAP_FLOW_2.equals(paySchDDTO.getCapFlow())) {//支出
                            tempList.add(0, paySchDDTO);
                        } else {
                            tempList.add(paySchDDTO);
                        }
                        payLastMap.put(paySchDDTO.getPaySchId(), tempList);
                    }else{
                        paySchDDTOList.add(paySchDDTO);
                    }
                    continue;
                }
                if (ovdMap != null && ovdMap.containsKey(paySchDDTO.getPaySchId())) {
                    CapOverdueInfoDTO dto = ovdMap.get(paySchDDTO.getPaySchId());
                    PrjPrdPaySchDDTO paySchD = new PrjPrdPaySchDDTO();
                    //逾期ID
                    paySchD.setId(dto.getId());
                    paySchD.setPaySchId(dto.getPaySchId());
                    paySchD.setPaySchNo(paySchDDTO.getPaySchNo());
                    paySchD.setPayPd(Integer.valueOf(String.valueOf(dto.getPayPd())));
                    paySchD.setFeeTypCd(CapitalConstant.CODE_FEE_TYP_CD_S05);
                    paySchD.setPayDt(dto.getCreateDate());
                    //未付罚息
                    paySchD.setArAmt(dto.getPenaltyAmount() - dto.getPayAmount());
                    //已付罚息
                    paySchD.setPaidUpAmt(dto.getPayAmount());
                    //应收金额
                    paySchD.setFeeAmt(Double.valueOf(dto.getPenaltyAmount()));
                    //收入
                    paySchD.setCapFlow(CapitalConstant.CODE_CAP_FLOW_1);
                    paySchDDTOList.add(paySchD);
                    ovdMap.remove(paySchDDTO.getPaySchId());
                }
                paySchDDTOList.add(paySchDDTO);
            }
            //添加最后的期末款
            if(StringUtils.isNotEmpty(paySchId)&&payLastMap.containsKey(paySchId)){
                paySchDDTOList.addAll(payLastMap.get(paySchId));
            }
            return paySchDDTOList;
        }
        return null;
    }

    /******************************
     * 资金分解，查询待分解支付表集合,手动核销页面
     * @param condition
     * @return
     * @throws BaseException
     ******************************/
    @Override
    public List<PrjPrdPaySchDVO> searchPaySchDList(CapFundQueryCondition condition) throws BaseException {
        //查询支付表明细时排除租金和剩余本金
        condition.setAdditionalCondition("S01,S04");
        //过滤小贷亿联
        Map<String, SysDictionaryDTO> CAP0076 = this.sysDictionaryApiService.searchGroupToObjMap(CurrentThreadContext.getCurrentSysCd(),
                CurrentThreadContext.getCurrentOrgCd(), "CAP0076");
        if(CollectionUtils.isMapNotEmpty(CAP0076)){
        	condition.setNotInLoanChannl(new ArrayList<String>(CAP0076.keySet()));
        }
        List<PrjPrdPaySchDDTO> dtoList = this.searchPrdPaySchDList(condition);
        List<PrjPrdPaySchDVO> voList = null;
        if (CollectionUtils.isNotEmpty(dtoList)) {
            //排除不需要核销的费用项 0：不需要核销 1：需要核销 2：只能手工核销 3：只能自动核销
            List<SysDictionaryDTO> dictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(),
                    CurrentThreadContext.getCurrentOrgCd(), PrjPrdPaySchDConstant.CODE_FEE_TYP_CD);
            Map<String, SysDictionaryDTO> feeTypCdMap = null;
            if (CollectionUtils.isNotEmpty(dictionaryDTOList)) {
                feeTypCdMap = new HashMap<>(dictionaryDTOList.size());
                for (SysDictionaryDTO dict : dictionaryDTOList) {
                    feeTypCdMap.put(dict.getCode(), dict);
                }
            }
            List<PrjPrdPaySchDVO> paySchDVOList = PrjPrdPaySchDVOTransform.toVOList(dtoList);
            if (CollectionUtils.isNotEmpty(paySchDVOList)) {
                SysDictionaryDTO dictionaryDTO = null;
                voList = new ArrayList<>(paySchDVOList.size());
                for (PrjPrdPaySchDVO vo : paySchDVOList) {
                    if (feeTypCdMap != null && feeTypCdMap.containsKey(vo.getFeeTypCd())) {
                        dictionaryDTO = feeTypCdMap.get(vo.getFeeTypCd());
                        //排除不需要核销的费用项 0：不需要核销 1：需要核销 2：只能手工核销 3：只能自动核销
                        if (StringUtils.isNotBlank(dictionaryDTO.getCodeDesc())
                                && ("0".equals(dictionaryDTO.getCodeDesc())
                                ||"3".equals(dictionaryDTO.getCodeDesc()))) {//不需要核销
                            continue;
                        }
                        if (vo.getPayPd() == 0l) {
                            vo.setFeeTypCdNm(dictionaryDTO.getCodeNm());
                        } else {
                            if (CapitalConstant.CODE_FEE_TYP_CD_S05.equals(vo.getFeeTypCd())) {
                                vo.setFeeTypCdNm(dictionaryDTO.getCodeNm());//罚息
                            } else {
                                vo.setFeeTypCdNm("第" + vo.getPayPd() + "期" + dictionaryDTO.getCodeNm());
                            }
                        }
                        if (StringUtils.isNotBlank(vo.getCapFlow()) && CapitalConstant.CODE_CAP_FLOW_2.equals(vo.getCapFlow())) {//支出为负
                            vo.setFeeAmt(-vo.getFeeAmt());
                            vo.setArAmt(-vo.getArAmt());
                            if (StringUtils.isNotEmpty(vo.getPaidUpAmt())) {
                                vo.setPaidUpAmt(-vo.getPaidUpAmt());
                            }
                        }
                    }
                    voList.add(vo);
                }
                dictionaryDTO = null;
                paySchDVOList.clear();
                paySchDVOList = null;
            }
        }
        return voList;
    }

    // 是否开启异常数据核销
    @Override
    public boolean isOpenAbnormalDecompose(){
        SysCtrlCfgQueryCondition qc = new SysCtrlCfgQueryCondition();
        qc.setSysCd(CapitalConstant.SYSCD);
        qc.setOrgCd(CapitalConstant.SYSORG);
        qc.setCtrlCode("CTRL_VFCAP_0001");
        //查询租金短信提醒开关配置值
        String code = this.sysCtrlCfgApiService.searchSysCtrlCfgByCtrlCode(qc);
        if ("1".equals(code)) {
            return true;
        }
        return false;
    }


    @Override
    public List<BillItemVO> queryBillItemList(CapFundQueryCondition condition) {
        QueryPeriodBillInfoParam queryParam = new QueryPeriodBillInfoParam();
        queryParam.setQueryCmd(QueryPeriodBillInfoParam.QueryCmd.QUERY_BY_CST_ID);
        queryParam.setQueryChannel(QueryPeriodBillInfoParam.QueryChannel.WEB_VF);
        queryParam.setQueryPurpose(QueryPeriodBillInfoParam.QueryPurpose.WEB_MANUAL_VF);
        queryParam.setCstId(condition.getCstId());
        queryParam.setQueryTime(condition.getAcceptActualDate());
        return queryBillItemList(queryParam);
    }

    @Override
    public List<BillItemVO> queryNotEnabledBillItemList(CapFundQueryCondition condition) {
        QueryPeriodBillInfoParam queryParam = new QueryPeriodBillInfoParam();
        queryParam.setQueryCmd(QueryPeriodBillInfoParam.QueryCmd.QUERY_BY_CST_ID);
        queryParam.setQueryChannel(QueryPeriodBillInfoParam.QueryChannel.WEB_VF);
        queryParam.setQueryPurpose(QueryPeriodBillInfoParam.QueryPurpose.WEB_ABNORMAL_VF);
        queryParam.setCstId(condition.getCstId());
        queryParam.setQueryTime(condition.getAcceptActualDate());
        return queryBillItemList(queryParam);
    }

    private List<BillItemVO> queryBillItemList(QueryPeriodBillInfoParam queryParam) {
        ResponseData<List<BillInfoDTO>> listResponseData = repayBillApiService.queryPeriodBillList(queryParam);
        if (listResponseData.isSuccess()) {
            List<BillInfoDTO> billInfoDTOList = listResponseData.getData();
            if (CollectionUtils.isNotEmpty(billInfoDTOList)) {
                List<SysDictionaryDTO> dictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(),
                        CurrentThreadContext.getCurrentOrgCd(), PrjPrdPaySchDConstant.CODE_FEE_TYP_CD);
                Map<String, SysDictionaryDTO> feeTypCdMap = Maps.newHashMap();
                if (CollectionUtils.isNotEmpty(dictionaryDTOList)) {
                    feeTypCdMap = new HashMap<>(dictionaryDTOList.size());
                    for (SysDictionaryDTO dict : dictionaryDTOList) {
                        feeTypCdMap.put(dict.getCode(), dict);
                    }
                }

                List<BillItemVO> billItemVOList = Lists.newArrayList();
                for (BillInfoDTO billInfo : billInfoDTOList) {
                    List<BillItemVO> billItemVOS = buildItemVOList(billInfo);
                    List<BillItemVO> headItemVOList = Lists.newArrayList();
                    BillItemVO s05 = null;
                    List<BillItemVO> bodyItemVOList = Lists.newArrayList();
                    List<BillItemVO> lastItemVOList = Lists.newArrayList();
                    for (BillItemVO billItemVO : billItemVOS) {
                        SysDictionaryDTO dictionaryDTO = feeTypCdMap.get(billItemVO.getFeeTypCd());
                        if (null != dictionaryDTO) {
                            // 排除不需要核销的费用项 0：不需要核销 1：需要核销 2：只能手工核销 3：只能自动核销
                            if ("0".equals(dictionaryDTO.getCodeDesc()) || "3".equals(dictionaryDTO.getCodeDesc())) {
                                //不需要核销
                                continue;
                            }
                            if (Integer.valueOf(0).equals(billItemVO.getPayPd())) {
                                if ("2".equals(billItemVO.getCntWayCd()) || "4".equals(billItemVO.getCntWayCd())) {
                                    // 计入融资额、合同额的支付表明细不需要核销
                                    continue;
                                }
                                billItemVO.setFeeTypCdNm(dictionaryDTO.getCodeNm());
                                //计入期末款的最后核销
                                if (CapitalConstant.CODE_CNT_WAY_CD_5.equals(billItemVO.getCntWayCd())) {
                                    if (CapitalConstant.CODE_CAP_FLOW_2.equals(billItemVO.getCapFlow())) {//支出
                                        lastItemVOList.add(0, billItemVO);
                                    } else {
                                        lastItemVOList.add(billItemVO);
                                    }
                                }else {
                                    headItemVOList.add(billItemVO);
                                }
                            } else {
                                if (CapitalConstant.CODE_FEE_TYP_CD_S05.equals(billItemVO.getFeeTypCd())) {
                                    billItemVO.setFeeTypCdNm(dictionaryDTO.getCodeNm());//罚息
                                    s05 = billItemVO;
                                } else {
                                    billItemVO.setFeeTypCdNm("第" + billItemVO.getPayPd() + "期" + dictionaryDTO.getCodeNm());
                                    bodyItemVOList.add(billItemVO);
                                }
                            }
                        }
                    }
                    bodyItemVOList.sort(Comparator.comparingInt(BillItemVO::getPayPd)
                            .thenComparing(BillItemVO::getFeeTypCd));
                    if (!headItemVOList.isEmpty()) {
                        billItemVOList.addAll(headItemVOList);
                    }
                    if (null != s05) {
                        billItemVOList.add(s05);
                    }
                    if (!bodyItemVOList.isEmpty()) {
                        billItemVOList.addAll(bodyItemVOList);
                    }
                    if (!lastItemVOList.isEmpty()) {
                        billItemVOList.addAll(lastItemVOList);
                    }
                }
                return billItemVOList;
            }
        }
        return null;
    }

    private List<BillItemVO> buildItemVOList(BillInfoDTO billInfo) {
        List<BillItemVO> list = Lists.newArrayList();
        List<BillItemDTO> billItems = billInfo.getBillItems();
        if (CollectionUtils.isNotEmpty(billItems)) {
            Long billId = billInfo.getBillId();
            String billNo = billInfo.getBillNo();
            Integer canRepay = billInfo.getCanRepay();
            String repayPrompt = billInfo.getRepayPrompt();
            String bizTypCd = billInfo.getBizTypCd();
            for (BillItemDTO dto : billItems) {
                BillItemVO billItemVO = new BillItemVO();
                billItemVO.setId(dto.getId());
                billItemVO.setPaySchId(billId);
                billItemVO.setPaySchNo(billNo);
                if("1".equals(billInfo.getBusinessLine())){
                    if (CapitalConstant.CODE_FEE_TYP_CD_S02.equals(dto.getFeeTypCd())
                            || CapitalConstant.CODE_FEE_TYP_CD_S03.equals(dto.getFeeTypCd())
                            || CapitalConstant.CODE_FEE_TYP_CD_S05.equals(dto.getFeeTypCd())) {
                        billItemVO.setCanRepay(canRepay);
                        billItemVO.setRepayPrompt(repayPrompt);
                    }else{
                        // 车贷费用项不限制
                        billItemVO.setCanRepay(1);
                    }
                }else{
                    // 其他不限制
                    billItemVO.setCanRepay(1);
                }
                billItemVO.setPayDt(dto.getPayDt());
                billItemVO.setPayPd(dto.getPayPd());
                billItemVO.setFeeTypCd(dto.getFeeTypCd());
                billItemVO.setCapFlow(dto.getCapFlow()+"");
                billItemVO.setCntWayCd(dto.getCntWayCd());
                billItemVO.setFeeAmt(dto.getFeeAmt());
                billItemVO.setPaidUpAmt(dto.getPaidUpAmt());
                billItemVO.setArAmt(dto.getArAmt());
                billItemVO.setBizTypCd(bizTypCd);
                if (CapitalConstant.CODE_CAP_FLOW_2.equals(billItemVO.getCapFlow())) {//支出为负
                    billItemVO.setFeeAmt(-billItemVO.getFeeAmt());
                    billItemVO.setArAmt(-billItemVO.getArAmt());
                    if (StringUtils.isNotEmpty(billItemVO.getPaidUpAmt())) {
                        billItemVO.setPaidUpAmt(-billItemVO.getPaidUpAmt());
                    }
                }
                list.add(billItemVO);
            }
        }
        return list;
    }

    /**
     * 查询客户支付表首付款明细
     *
     * @param condition
     * @return
     * @throws BaseException
     */
    @Override
    public List<PrjPrdPaySchDVO> searchFstPayList(CapFundQueryCondition condition) throws BaseException {
        PrjPrdPaySchDQueryCondition qc = new PrjPrdPaySchDQueryCondition();
        if (StringUtils.isNotEmpty(condition.getCstId())) {
            qc.setCstId(condition.getCstId());//客户ID
        }
        if (StringUtils.isNotEmpty(condition.getPayPd())) {
            qc.setPayPd(condition.getPayPd());
        }
        if (StringUtils.isNotEmpty(condition.getPaySchId())) {
            qc.setPaySchId(condition.getPaySchId());
        }
        if (CollectionUtils.isNotEmpty(condition.getPaySchIdList())) {
            qc.setPaySchIdList(condition.getPaySchIdList());
        }
        //qc.setSortName(" M.ID,D.ID ");
        qc.setSortName("PAY_SCH_ID,ID");
        qc.setCntWayCd(CapitalConstant.CODE_CNT_WAY_CD_1);//首期款
        BaseLogUtils.info(logger, "searchFstPayList", "查询客户支付表首付款明细.DATA:" + JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
        //List<PrjPrdPaySchDDTO> dtoList = prjPrdPaySchDApiService.searchPrjPrdPaySchDList(qc);
        List<PrjPrdPaySchDDTO> dtoList = prjPrdPaySchDApiService.searchVfPaySchDList(qc);
        List<PrjPrdPaySchDVO> voList = null;
        if (CollectionUtils.isNotEmpty(dtoList)) {
            List<SysDictionaryDTO> dictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(),
                    CurrentThreadContext.getCurrentOrgCd(), PrjPrdPaySchDConstant.CODE_FEE_TYP_CD);//费用类型数据字典
            Map<String, SysDictionaryDTO> feeTypCdMap = null;
            if (CollectionUtils.isNotEmpty(dictionaryDTOList)) {
                feeTypCdMap = new HashMap<>(dictionaryDTOList.size());
                for (SysDictionaryDTO dict : dictionaryDTOList) {
                    feeTypCdMap.put(dict.getCode(), dict);
                }
            }
            List<PrjPrdPaySchDVO> paySchDVOList = PrjPrdPaySchDVOTransform.toVOList(dtoList);
            if (CollectionUtils.isNotEmpty(paySchDVOList)) {
                SysDictionaryDTO dictionaryDTO = null;
                voList = new ArrayList<>(paySchDVOList.size());
                for (PrjPrdPaySchDVO vo : paySchDVOList) {
                    if (feeTypCdMap != null && feeTypCdMap.containsKey(vo.getFeeTypCd())) {
                        dictionaryDTO = feeTypCdMap.get(vo.getFeeTypCd());
                        //排除不需要核销的费用项 0：不需要核销 1：需要核销 2：只能手工核销 3：只能自动核销
                        if (StringUtils.isNotBlank(dictionaryDTO.getCodeDesc())
                                && ("0".equals(dictionaryDTO.getCodeDesc())||"2".equals(dictionaryDTO.getCodeDesc()))) {
                            continue;
                        }
                        vo.setFeeTypCdNm(dictionaryDTO.getCodeNm());
                    }
                    voList.add(vo);
                }
                dictionaryDTO = null;
                paySchDVOList.clear();
                paySchDVOList = null;
            }
        }
        return voList;
    }

    /**
     * 查询分解资金可否冲红
     *
     * @param fundId
     * @return
     * @throws BaseException
     */
    public boolean validateFundRevert(Long fundId) throws BaseException {
        if (null == fundId) {
            return false;
        }
        return this.capFundApiService.valideFundRevert(fundId);
    }

    /**
     * 验证资金可否修改
     *
     * @param idList
     * @return
     * @throws BaseException
     */
    public DataResultVO validateDecomFund(List<Long> idList) throws BaseException {
        if (CollectionUtils.isEmpty(idList)) {
            return new DataResultVO(0, "未找到核销资金信息");
        }
        DataResultDTO resultDTO = this.capFundApiService.validateDecomFund(idList);
        if (null != resultDTO) {
            return new DataResultVO("1".equals(resultDTO.getCode()) ? 1 : 0, resultDTO.getInfo());
        } else {
            return new DataResultVO(0, "未找到核销资金信息");
        }
    }

    /**
     * 查询认款客户
     *
     * @return
     * @throws BaseException
     */
    @Override
    public Pager searchCstListPage(Pager page) throws BaseException {
        CapFundQueryCondition condition = (CapFundQueryCondition) page.getCondition();
        condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
        condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
        condition.setUsrId(CurrentThreadContext.getCurrentUserId());

        Pager pager = this.capFundApiService.searchPrjCstListPage(page);
        if (pager != null && CollectionUtils.isNotEmpty(pager.getResultList())) {
            List<CapPayInfoVO> voList = CapPayInfoVOTransform.toVOList((List<CapPayInfoDTO>) pager.getResultList());
            pager.setResultList(voList);
            List<Long> idList = new ArrayList<>();
            for (CapPayInfoVO vo : voList) {
                if (idList.contains(vo.getCstId())) {
                    continue;
                }
                idList.add(vo.getCstId());
            }

            CstBscInfoQueryCondition cstBscInfoQueryCondition = new CstBscInfoQueryCondition();
            cstBscInfoQueryCondition.setIds(idList);
            List<CstBscInfoDTO> cstList = customerQueryApiService.searchCstBscInfoList(cstBscInfoQueryCondition);
            Map<Long, CstBscInfoDTO> cstMap = new HashMap<>();
            for (CstBscInfoDTO cstBscInfoDTO : cstList) {
                cstMap.put(cstBscInfoDTO.getId(), cstBscInfoDTO);
            }

            for (CapPayInfoVO vo : voList) {
                if (cstMap.containsKey(vo.getCstId())) {
                    vo.setCertNo(cstMap.get(vo.getCstId()).getCertNo());//暂时存放客户证件号、组织机构代码
                }
            }
        }
        return pager;
    }

    /**
     * 添加数据字典名称
     *
     * @param voList
     */
    public void setDictData(List<CapFundVO> voList) {
        if (CollectionUtils.isEmpty(voList)) return;
        Map<String, String> fundStatusCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), CapitalConstant.CODE_CAP_FUND_STS_CD);
        Map<String, String> fundTypCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), CapitalConstant.CODE_CAP_FUND_TYP_CD);
        Map<String, String> capTypCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), CapitalConstant.CODE_CAP_TYP_CD);

        for (CapFundVO vo : voList) {
            if (fundStatusCdMap != null && fundStatusCdMap.containsKey(vo.getFundStatusCd())) {
                vo.setFundStatusCdNm(fundStatusCdMap.get(vo.getFundStatusCd()));
            }
            if (fundTypCdMap != null && fundTypCdMap.containsKey(vo.getFundTypCd())) {
                vo.setFundTypCdNm(fundTypCdMap.get(vo.getFundTypCd()));
            }
            if (StringUtils.isNotBlank(vo.getFundBelongOrgCd())) {
                SysOrgDTO org = this.sysOrgApiService.selectSysOrgByOrgCd(vo.getFundBelongOrgCd(), CurrentThreadContext.getCurrentSysCd());
                if (org != null) {
                    vo.setFundBelongOrgCdNm(org.getOrgNm());
                }
            }
            if (capTypCdMap != null && capTypCdMap.containsKey(vo.getCapTypCd())) {
                vo.setCapTypCdNm(capTypCdMap.get(vo.getCapTypCd()));
            }

        }
    }


    /**
     * 添加支付表费用，查询流程发起时间
     *
     * @param prjPrdPaySchDVO
     * @return
     * @throws BaseException
     */
    @Override
    public Date getAddFeeFlowStartTime(PrjPrdPaySchDVO prjPrdPaySchDVO) throws BaseException {
        //查询添加风险保证金流程信息
        SysFlowSHQueryCondition condition = new SysFlowSHQueryCondition();
        condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
        condition.setDataId(prjPrdPaySchDVO.getId());
        condition.setWordsInTheTable(PrjBscInfoConstant.PRJ_FLOW_S_H_PRJ);
        condition.setStatus(1);
        List<SysFlowSHDTO> flowSHDTOList = flowQueryApiService.searchFlowSHList(condition);
        if (CollectionUtils.isNotEmpty(flowSHDTOList)) {
            SysFlowSHDTO flowSHDTO = flowSHDTOList.get(0);
            return flowSHDTO.getpCrtTm();//流程创建时间
        } else {
            return null;
        }
    }

    /**
     * 查询流程发起时间
     *
     * @param dataId 业务主键
     * @param bizTyp 业务类型 1.放款 2.添加风险保证金 3.结清
     * @return
     * @throws BaseException
     */
    public Date getFlowStartTime(Long dataId, String bizTyp) throws BaseException {
        SysFlowSHQueryCondition condition = new SysFlowSHQueryCondition();
        condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
        condition.setDataId(dataId);
        List<String> busTypList = new ArrayList<String>();
        if (CapitalConstant.CODE_BIZ_TYP_CD_1.equals(bizTyp)) {
            condition.setWordsInTheTable(CapPayInfoConstant.CAP_FLOW_S_H_CAP);
            busTypList.add(FlowConstant.FLOW_MODEL_TYP_CAP_PAY_NORMAL);
            busTypList.add(FlowConstant.FLOW_MODEL_TYP_CAP_PAY_ADVANCE);
            busTypList.add(FlowConstant.FLOW_MODEL_TYP_CAP_PAY_SPECIAL);
        } else if (CapitalConstant.CODE_BIZ_TYP_CD_2.equals(bizTyp)) {
            condition.setWordsInTheTable(PrjBscInfoConstant.PRJ_FLOW_S_H_PRJ);
            busTypList.add(FlowConstant.FLOW_MODEL_TYP_RISK);
        } else if (CapitalConstant.CODE_BIZ_TYP_CD_3.equals(bizTyp)) {
            condition.setWordsInTheTable(PrjBscInfoConstant.PRJ_FLOW_S_H_PRJ);
            busTypList.add(FlowConstant.FLOW_MODEL_TYP_SETTLE_NORMAL);
            busTypList.add(FlowConstant.FLOW_MODEL_TYP_SETTLE_ADVANCE);
        } else {
            BaseLogUtils.info(logger, "getFlowStartTime", "查询流程发起时间,业务类型未定义");
            return null;
        }
        if(CollectionUtils.isNotEmpty(busTypList)){
            condition.setBusTypList(busTypList);
        }
        condition.setStatus(1);
        List<SysFlowSHDTO> flowSHDTOList = flowQueryApiService.searchFlowSHList(condition);
        if (CollectionUtils.isNotEmpty(flowSHDTOList)) {
            SysFlowSHDTO flowSHDTO = flowSHDTOList.get(0);
            return flowSHDTO.getpCrtTm();//流程创建时间
        } else {
            return null;
        }
    }

    /**
     * 修改支付表
     *
     * @param dataId
     * @return
     * @throws BaseException
     */
    @Override
    public boolean modifyPaySchById(Long dataId) throws BaseException {
        BaseLogUtils.info(logger, "modifyPaySchById", "修改支付表[" + dataId + "]==>");
        boolean flag = prjPrdPaySchMApiService.modifyAndRemovePrjPrdPaySchByPaySchId(dataId, CurrentThreadContext.getCurrentUserId());
        BaseLogUtils.info(logger, "modifyPaySchById", "修改支付表[" + dataId + "]==>" + flag);
        return flag;
    }

    /**
     * 导出资金列表
     *
     * @param condition
     * @return
     * @throws BaseException
     */
    @Override
    public DataResultVO exportFundList(CapFundExportCondition condition) throws BaseException {
        if (condition == null) {
            condition = new CapFundExportCondition();
        }
        condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
        condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
        //查询条件为空 默认导出未分解数据
        /*if (StringUtils.isBlank(condition.getComeNameAlias()) && StringUtils.isEmpty(condition.getAmount())
                && StringUtils.isBlank(condition.getAcceptDateMin()) && StringUtils.isBlank(condition.getAcceptDateMax())
                && StringUtils.isBlank(condition.getAcceptCode())) {
            condition.setFundStatusCd(CapitalConstant.CODE_OVD_STATUS_CD_0);
        }*/

        try {
            DataResultDTO resultDTO = this.capFundExportApiService.exportFundList(condition);
            if (null == resultDTO) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "导出失败");
            } else {
                return new DataResultVO(Integer.parseInt(resultDTO.getCode()), resultDTO.getInfo(), resultDTO.getData());
            }
        } catch (BaseException e) {
            BaseLogUtils.error(logger, "exportDecomposeList", "导出资金列表数据失败");
            BaseLogUtils.error(logger, "-", "异常", e);
        } catch (NumberFormatException e) {
            BaseLogUtils.error(logger, "exportDecomposeList", "导出资金列表数据失败");
            BaseLogUtils.error(logger, "-", "异常", e);
        }
        return new DataResultVO(BaseConstant.IS_YESNO_NO, "导出资金列表失败");


    }

    /**
     * 设置结清时间
     *
     * @param prjPrdDtlId
     * @param stlDt
     * @return
     * @throws BaseException
     */
    @Override
    public DataResultVO modifyStlDt(Long prjPrdDtlId, String stlDt) throws BaseException {
        try {
            PrjPrdDtlVO prjPrdDtlVO = this.prjPrdDtlService.selectById(prjPrdDtlId);
            if (null == prjPrdDtlVO) {
                BaseLogUtils.error(logger, "modifyStlDt", "保存结清时间失败,未找到项目产品明细==" + prjPrdDtlId);
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "保存结清时间失败");
            }

            prjPrdDtlVO.setStlDt(DateUtils.formatStringToDate(stlDt, DateUtils.YYYY_MM_DD));
            /*boolean flag = this.prjPrdDtlService.modify(prjPrdDtlVO);
            if (flag) {
                return new DataResultVO(BaseConstant.IS_YESNO_YES, "保存成功");
            } else {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "保存失败");
            }*/

            DataResultDTO resultDTO = this.capFundApiService.modifyStlDt(PrjPrdDtlVOTransform.toDTO(prjPrdDtlVO));
            if (null == resultDTO) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "保存失败");
            } else {
                return new DataResultVO(Integer.parseInt(resultDTO.getCode()), resultDTO.getInfo());
            }
        } catch (BaseException e) {
            BaseLogUtils.info(logger, "modifyStlDt", "保存结清时间失败,系统异常==" + prjPrdDtlId,e);
            BaseLogUtils.error(logger, "-", "异常", e);
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "系统异常，保存失败");
        }
    }

    /**
     * 查询费用项名称
     *
     * @param feeTypCd
     * @return
     * @throws BaseException
     */
    @Override
    public String getFeeTypCdNm(String feeTypCd) throws BaseException {
        SysDictionaryDTO  dto = this.sysDictionaryApiService.getCode(CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(), SysDictionaryConstant.CODE_PRJ_FEE_TYP_CD,feeTypCd);
        if(dto != null){
            return dto.getCodeNm();
        }
        return null;
    }


    /**
     * 批量修改资金表信息
     *
     * @param idsList
     * @return
     * @throws BaseException
     */
    @Override
    public  boolean ModifyListFundCstInfo(List<CapFundVO> idsList) throws BaseException {
        return this.capFundApiService.ModifyListFundCstInfo(CapFundVOTransform.toDTOList(idsList));
    }
    /**
     * 资金类型查询
     * @return
     * @throws BaseException
     */
    @Override
    public List<KeyValueVO> searchFundTypeCdList() throws BaseException {
        return this.getKvList(CapitalConstant.CODE_CAP_TYP_CD);//字典表查询 资金类型
    }
    /**
     * 根据字典中代码组值获取组员集合
     * @param grpCd 代码组值
     * @return 集合
     */
    private List<KeyValueVO> getKvList(String grpCd){
        List<KeyValueVO> kvList = new ArrayList<>();
        try {
            List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), grpCd);
            if(CollectionUtils.isNotEmpty(sysDictionaryDTOList)){
                for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                    KeyValueVO keyValueVO = new KeyValueVO();
                    keyValueVO.setKey(sysDictionaryDTO.getCode());
                    keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
                    kvList.add(keyValueVO);
                }
            }
        } catch (BaseException e) {
            BaseLogUtils.info(logger, "getKvList", "获取字典项组"+grpCd+"失败.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception e) {
            BaseLogUtils.error(logger, "getKvList", "获取字典项组"+grpCd+"失败,系统错误.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return kvList;
    }

    /**
     * 实现资金记录剩余资金计算方法
     */
    @Override
    public Map<Long, Long> searchfundVHList(List<CapFundOutLogVO> funid, List<CapFundVO> list) throws BaseException {
        Map<Long, Long> questionMap=null;
        if(CollectionUtils.isNotEmpty(funid)&&CollectionUtils.isNotEmpty(list)){
            questionMap =new HashMap<Long,Long>();
            for (int i = 0; i < list.size(); i++) {
                for (int j = 0; j < funid.size(); j++) {
                    //查询到的对象数组
                    Long fundId = funid.get(j).getFundId();
                    //固定的资金数据id
                    Long longValue = list.get(i).getId();
                    //比较两数是否相等
                    if(fundId.equals(longValue)){
                        // 转出金额
                        Long outAmt = funid.get(j).getOutAmt();
                        //收款金额[核销实收金额]
                        Long amount = list.get(i).getAmount();
                        //用收款金额 -转出金额=剩余可转金额
                        double outAmtFund = DecimalUtils.sub(amount.doubleValue(), outAmt.doubleValue());
                        long castAmtFund = Double.valueOf(outAmtFund).longValue();
                        questionMap.put(longValue, Long.valueOf(castAmtFund));
                        break;
                    }
                }
            }
        }
        return questionMap;
    }

    /**
     * 手动分解查询APP贷款账单 List
     * @param condition 资金QC
     * @return
     * @throws BaseException
     */
    @Override
    public List<PrjPrdPaySchDDTO> selectMcrBillList(CapFundQueryCondition condition) throws BaseException {
        if(null == condition){
            BaseLogUtils.info(logger,"selectMcrBillList","动分解查询APP贷款账单,条件不能为空！");
            return null ;
        }
        List<PrjPrdPaySchDDTO> prjPrdPaySchDDTOList = this.capFundApiService.selectMcrBillDList(condition);
        return prjPrdPaySchDDTOList;
    }

    /**
     * 只删除关联id
     * @param idsList id集合
     * @return
     * @throws BaseException
     */
	@Override
	public boolean deleteOnlyRelationPayIdByIds(List<Long> idsList) throws BaseException {
		if (CollectionUtils.isEmpty(idsList)) return false;
        return this.capFundApiService.deleteOnlyRelationPayIdByIds(idsList, CurrentThreadContext.getCurrentUserId());
	}

    @Override
    public boolean addChildFundFromParentFund(CapFundDTO capFundDTO) throws BaseException {
        if (CollectionUtils.isEmpty(capFundDTO.getIdList())) return false;
        if (capFundDTO.getRelationPayId() == null) return false;

        capFundDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
        capFundDTO.setCrtUsrNm(CurrentThreadContext.getCurrentUserName());

        return capFundApiService.addChildFundFromParentFund(capFundDTO);
    }

    @Override
    public boolean removeChildFund(Long childFundId) throws BaseException {
        return capFundApiService.removeChildFund(childFundId, CurrentThreadContext.getCurrentUserId(), CurrentThreadContext.getCurrentUserName());
    }

    @Override
    public boolean modifyChildFund(CapFundVO capFundVO) throws BaseException {
        capFundVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
        return capFundApiService.modifyChildFund(CapFundVOTransform.toDTO(capFundVO));
    }

	@Override
	public List<PrjPrdPaySchDVO> searchWSFeeList(Long paySchId) {
        List<PrjPrdPaySchDDTO> dtoList = this.prjPrdPaySchDApiService.searchWSFeeList(paySchId);
        List<PrjPrdPaySchDVO> voList = null;
        if (CollectionUtils.isNotEmpty(dtoList)) {
            //排除不需要核销的费用项 0：不需要核销 1：需要核销 2：只能手工核销 3：只能自动核销
            List<SysDictionaryDTO> dictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(),
                    CurrentThreadContext.getCurrentOrgCd(), PrjPrdPaySchDConstant.CODE_FEE_TYP_CD);
            Map<String, SysDictionaryDTO> feeTypCdMap = null;
            if (CollectionUtils.isNotEmpty(dictionaryDTOList)) {
                feeTypCdMap = new HashMap<>(dictionaryDTOList.size());
                for (SysDictionaryDTO dict : dictionaryDTOList) {
                    feeTypCdMap.put(dict.getCode(), dict);
                }
            }
            List<PrjPrdPaySchDVO> paySchDVOList = PrjPrdPaySchDVOTransform.toVOList(dtoList);
            if (CollectionUtils.isNotEmpty(paySchDVOList)) {
                SysDictionaryDTO dictionaryDTO = null;
                voList = new ArrayList<>(paySchDVOList.size());
                for (PrjPrdPaySchDVO vo : paySchDVOList) {
                    if (feeTypCdMap != null && feeTypCdMap.containsKey(vo.getFeeTypCd())) {
                        dictionaryDTO = feeTypCdMap.get(vo.getFeeTypCd());
                        //排除不需要核销的费用项 0：不需要核销 1：需要核销 2：只能手工核销 3：只能自动核销
                        if (StringUtils.isNotBlank(dictionaryDTO.getCodeDesc())
                                && ("0".equals(dictionaryDTO.getCodeDesc())
                                ||"3".equals(dictionaryDTO.getCodeDesc()))) {//不需要核销
                            continue;
                        }
                        if (vo.getPayPd() == 0l) {
                            vo.setFeeTypCdNm(dictionaryDTO.getCodeNm());
                        } else {
                            if (CapitalConstant.CODE_FEE_TYP_CD_S05.equals(vo.getFeeTypCd())) {
                                vo.setFeeTypCdNm(dictionaryDTO.getCodeNm());//罚息
                            } else {
                                vo.setFeeTypCdNm("第" + vo.getPayPd() + "期" + dictionaryDTO.getCodeNm());
                            }
                        }
                        if (StringUtils.isNotBlank(vo.getCapFlow()) && CapitalConstant.CODE_CAP_FLOW_2.equals(vo.getCapFlow())) {//支出为负
                            vo.setFeeAmt(-vo.getFeeAmt());
                            vo.setArAmt(-vo.getArAmt());
                            if (StringUtils.isNotEmpty(vo.getPaidUpAmt())) {
                                vo.setPaidUpAmt(-vo.getPaidUpAmt());
                            }
                        }
                    }
                    voList.add(vo);
                }
                dictionaryDTO = null;
                paySchDVOList.clear();
                paySchDVOList = null;
            }
        }
        return voList;
	}


    /**
     * 手动分解查询垫款贷账单明细 List
     * @param condition 资金QC
     * @return
     * @throws BaseException
     */
    @Override
    public List<PrjPrdPaySchDDTO> selectPblBillList(CapFundQueryCondition condition) throws BaseException {
        if(null == condition){
            BaseLogUtils.newLogger("手动分解查询垫款贷账单,条件不能为空！").setKeys("selectPblBillList",CurrentThreadContext.getCurrentUserName()).info();
            return null ;
        }
        List<PrjPrdPaySchDDTO> prjPrdPaySchDDTOList = this.capFundApiService.selectPblBillDList(condition);
        return prjPrdPaySchDDTOList;
    }
    
}
